home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 17999 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.5 KB

  1. Path: news.sprintlink.net!datalytics!usenet
  2. From: Rob Stewart <stew@datalytics.com>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: ? Accessing members of classes within classes
  5. Date: Thu, 18 Apr 1996 09:33:01 -0400
  6. Organization: Datalytics, Inc
  7. Message-ID: <3176448D.13D2@datalytics.com>
  8. References: <4l3k7a$rjo@hammer.msfc.nasa.gov>
  9. NNTP-Posting-Host: 204.62.224.71
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.0 (WinNT; I)
  14.  
  15. NS130355@ wrote:
  16. > What is the proper method of accessing the public members
  17. > of a class used in a "has a" relationship within another
  18. > class as a public member?
  19.  
  20. Make them private and provide accessor/modifier functions!
  21.  
  22. > Example:
  23. > class firstClass
  24. >    {
  25. >      private:  char mydata[10];
  26. >       public:  int setMydata(char *);
  27. >                char* getMydata(void);
  28. >    }
  29.  
  30. ------^
  31. missing semicolon
  32.  
  33. > class secondClass
  34. >    {
  35. >       private:  char mydata2[10];
  36. >       public:   firstClass cMember[10];
  37. >                 int setMydata2(char *);
  38. >                 char* getMydata2(void);
  39. >    }
  40.  
  41. ------^
  42. missing semicolon
  43.  
  44. > int main
  45.  
  46. ----------^
  47. missing parameter list (even "(void)")
  48.  
  49. > {
  50. >    // THIS DOESN'T COMPILE.  WHY?
  51. >    secondClass myObject;
  52. >    myObject.cMember[0].setMydata("HELLO");
  53.  
  54. I don't see anything wrong with this and it compiles on VC 4.1.  
  55. Neither is conclusive, but I think your compiler is at fault.
  56.  
  57. [snip]
  58.  
  59. -- 
  60. Robert Stewart        | My opinions are usually my own.
  61. Datalytics, Inc.    | stew@datalytics.com
  62.